/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package generatorGraphics.graphics;

import grammaticalClasses.nwConsole.ShowStatShort;
import grammaticalClasses.nwConsole.ShowStatus;
import java.awt.Color;
import java.awt.Dimension;
import java.util.ArrayList;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;

/**
 *
 * @author Heitor
 */
public class MoteNetwork extends Graph {
    
    public MoteNetwork(){
        name = "Mote Network";
        help = "Help of Mote in Network";
        
        //configUnitOptions();
        
        commands.add("ShowStatus");
        commands.add("ShowNetwork");
    }
    
    @Override
    protected void createGraph(String unit){
        
        int indice = search.getAnswer(commands, "ShowStatus");
        
        chartPanel = new ChartPanel(buildGraph((ArrayList<ShowStatus>) answer.get(indice)));
        chartPanel.setBackground(Color.LIGHT_GRAY);
        chartPanel.setPreferredSize(new Dimension(700, 350)); 
        chartPanel.setDomainZoomable(false);
        chartPanel.setRangeZoomable(false);
        
    }
    
    private JFreeChart buildGraph(ArrayList<ShowStatus> auxStatus){
    
        DefaultPieDataset defaultpiedataset = new DefaultPieDataset();
        if(auxStatus.size() > 0){
            defaultpiedataset.setValue("Live", auxStatus.get(0).getLiveMotes());
            defaultpiedataset.setValue("Network", auxStatus.get(0).getNetworkMotes());
            defaultpiedataset.setValue("Connected", auxStatus.get(0).getConnectedMotes());
        }
        
        JFreeChart jfreechart = ChartFactory.createPieChart("Motes", defaultpiedataset, true, true, false);
        jfreechart.setBackgroundPaint(new Color(238, 238, 238));
        PiePlot pieplot = (PiePlot)jfreechart.getPlot();
        
        pieplot.setSimpleLabels(true);
        pieplot.setInteriorGap(0.0D);
        return jfreechart;
    
    }
    
    @Override
    public ChartPanel getChartPanel() {
        
        if(search != null){
            createGraph("");
            return chartPanel;
        } else {
            return new ChartPanel(null);
        }
    }
    
}
